#ifndef __EVENT_FLAGS_H
#define __EVENT_FLAGS_H

#include "../rtx/rtx_os.h"

#define EVENT_FLAGS_INFO(NAME)                                                 \
    static uint64_t                                                            \
        NAME##_event_flags_cb_mem[(osRtxEventFlagsCbSize + 7) / 8];            \
    static osEventFlagsId_t NAME##_event_flags_id;                             \
    static inline void NAME##_event_flags_create() {                           \
        osEventFlagsAttr_t attr = {                                            \
            .name = #NAME,                                                     \
            .attr_bits = 0,                                                    \
            .cb_mem = NAME##_event_flags_cb_mem,                               \
            .cb_size = osRtxEventFlagsCbSize,                                  \
        };                                                                     \
        NAME##_event_flags_id = osEventFlagsNew(&attr);                        \
    }                                                                          \
    static inline uint32_t NAME##_event_flags_set(uint32_t flags) {            \
        return osEventFlagsSet(NAME##_event_flags_id, flags);                  \
    }                                                                          \
    static inline uint32_t NAME##_event_flags_clear(uint32_t flags) {          \
        return osEventFlagsClear(NAME##_event_flags_id, flags);                \
    }                                                                          \
    static inline uint32_t NAME##_event_flags_wait_any(uint32_t flags,         \
                                                       uint32_t timeout) {     \
        return osEventFlagsWait(NAME##_event_flags_id, flags, osFlagsWaitAny,  \
                                timeout);                                      \
    }                                                                          \
    static inline uint32_t NAME##_event_flags_wait_all(uint32_t flags,         \
                                                       uint32_t timeout) {     \
        return osEventFlagsWait(NAME##_event_flags_id, flags, osFlagsWaitAll,  \
                                timeout);                                      \
    }

#endif
